package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.HeartMark;
import com.czh.springboot04.service.HeartMarkService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/heartMark")
public class HeartMarkController {
    @Autowired
    private HeartMarkService heartMarkService;

    @PostMapping("/addHeartMark")
    public R addHeartMark(@RequestBody HeartMark heartMark){
        int i=heartMarkService.addHeartMark(heartMark);
        if(i>0 ){
            return R.ok(heartMark);
        }else {
            return R.fail("添加失败");
        }
    }
    @PutMapping("updateHeartMark")
    public R updateHeartMark(@RequestBody HeartMark heartMark){
        System.out.println( heartMark);
        int i=heartMarkService.updateHeartMark(heartMark);
        if(i> 0 ){
            return R.ok("修改成功");
        }else {
            return R.fail("失败");
        }
    }
    @DeleteMapping("/{id}")
    public R deleteHeartMark(@PathVariable("id")int id){
        int i=heartMarkService.deleteHeartMark(id);
        if(i> 0 ){
            return R.ok("删除成功");
        }else {
            return R.fail("失败");
        }
    }
    @GetMapping("finAll")
    public R findAll(@RequestParam(required = false,defaultValue = "1") int pageNum,
                     @RequestParam(required = false,defaultValue = "3") int pageSize){
        PageInfo<HeartMark> pageInfo=heartMarkService.findAll( pageNum,pageSize);
        return R.ok(pageInfo);
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable("id")int id){
        HeartMark heartMark=heartMarkService.findById(id);
        return R.ok(heartMark);
    }
}
